
window.addEvent('domready', function() {
	if ($('comment_box')) {
		$('comment_box').className = 'invisible';
	}
});

function showCommentBox(id) {
	var id = document.getElementById(id);
	id.style.visibility = 'visible';
}

function validateAll() {
	var j = 0;
	var option = [];
	var element = document.getElementsByTagName("input");
	for ( var i = 0; i < element.length; i++) {
		if (element[i].className == "required") {

			if (element[i].type == "text") {
				if (element[i].value == "") {
					alert("Enter Required Fields");
					return false;
				}
			}

			if (element[i].type == "radio") {
				if (element[i].name == element[i + 1].name) {
					option[j] = element[i];
					j++;
				} else {
					option[option.length] = element[i];
					j = 0;
					var flag = false;
					for ( var k = 0; k < option.length; k++) {
						if (option[k].checked) {
							flag = true;
						}
					}
					option = [];
					if (!flag) {
						alert("Enter Required Fields");
						return false;
					}
				}
			}

			if (element[i].type == "checkbox") {
				var s1 = element[i].name.split("_");
				var s2 = element[i + 1].name.split("_");

				if (s1[2] == s2[2]) {
					option[j] = element[i];
					j++;
				} else {
					option[option.length] = element[i];
					j = 0;
					var flag = false;
					for ( var k = 0; k < option.length; k++) {
						if (option[k].checked) {
							flag = true;
						}
					}
					option = [];
					if (!flag) {
						alert("Enter Required Fields");
						return false;
					}
				}
			}

		}

		if (element[i].title == "Enter Number Only") {
			var numericExpression = /^[0-9]+$/;
			if (element[i].value != "") {
				if (!element[i].value.match(numericExpression)) {
					alert("Please enter numbers only");
					element[i].focus;
					return false;
				}
			}
		}

		if (element[i].title == "Enter Date Only") {
			var numericExpression = /^[0-9]+$/;
			if (element[i].value != "") {
				var date_info = element[i].value.split("-");
				if (date_info.length != 3) {
					alert("Please enter the date in right format as described (YYYY-mm-dd)");
					return false;
				} else {
					for ( var n = 0; n < 3; n++) {
						if (!date_info[n].match(numericExpression)) {
							alert("Please enter correct Date (YYYY-MM-DD)");
							element[i].focus;
							return false;
						}
					}

					if (date_info[0].length != 4) {
						alert("Please enter 4 digit year number in this format (YYYY-MM-DD)");
						element[i].focus;
						return false;
					}

					if (date_info[1].length != 2) {
						alert("Please enter 2 digit month number in this format (YYYY-MM-DD)");
						element[i].focus;
						return false;

					}

					if (date_info[1] > 12 || date_info[1] < 1) {
						alert("Please Enter Correct month (less then 12 and greater than 1)");
						element[i].focus;
						return false;

					}

					if (date_info[2].length != 2) {
						alert("Please enter 2 digit Day number in this format (YYYY-MM-DD)");
						element[i].focus;
						return false;

					}

					if (date_info[2] > 31 || date_info[1] < 1) {
						alert("Please Enter Correct Day (less then 31 and greater than 1)");
						element[i].focus;
						return false;

					}
				}
			}
		}

	}

	var droplist = document.getElementsByTagName("select");
	for ( var d = 0; d < droplist.length; d++) {
		if (droplist[d].className == "required") {
			if (droplist[d].selectedIndex == 0) {
				alert("Please select any one option from Drop Down List.");
				return false;
			}
		}
	}

	return true;
}